import Vue from 'vue'
import VueRouter from 'vue-router'

const Home = () => import('../views/home/home')
const Category = () => import('../views/category/category')
const Shop = () => import('../views/shop/shop')
const Mine = () => import('../views/mine/mine')
const Detail = () => import('../views/detail/Detail')


//安装使用router
Vue.use(VueRouter);
//以下代码解决路由地址重复点击的报错问题
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
   {
      path: '',
      redirect: '/home'
   },
   {
      path: '/home',
      component: Home
   },
   {
      path: '/category',
      component: Category
   },
   {
      path: '/shop',
      component: Shop
   },
   {
      path: '/mine',
      component: Mine
   },
   {
      path: '/detail/:iid',
      component: Detail
   }
]
const router = new VueRouter({
   mode: 'history',
   routes
})

export default router
